<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>商品添加</title>
<link href="<%=basePath%>skin/css/validform/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=basePath%>skin/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>skin/js/validform/Validform_v5.3.2_min.js"></script>
<script type="text/javascript" src="<%=basePath%>skin/js/editor/kindeditor.js"></script>
<script type="text/javascript" src="<%=basePath%>skin/js/jquery.tools.js"></script>
<script type="text/javascript" src="<%=basePath%>skin/js/common.js"></script>
<script language="javascript">
	 var productImageIndex = 0;
	 $().ready(function(){
		//验证
		var validform = $("#form1").Validform({
			btnSubmit:"#save",
			tiptype:3,
			datatype:{
				"decimal":function(gets,obj,curform,regxp){
					var decimalReg=/^\d{0,8}\.{0,1}(\d{1,2})?$/;
					if(gets == null || gets == ""){
						return "请填写信息";
					}
					if(decimalReg.test(gets)){
						return true;
					}
					return "请填写数字或小数";
				}
			}
		});
		validform.addRule([
			{
			    ele:"#sn",
			    datatype:"n",
			    nullmsg:"请输入编号！"
			},
			{
			    ele:"#name",
			    datatype:"*",
			    nullmsg:"请输入名称！"
			},
			{
			    ele:"#description",
			    datatype:"*",
			    nullmsg:"请输入描述！"
			},
			{
			    ele:"#price",
			    datatype:"decimal",
			    nullmsg:"请输入销售价！"
			},
			{
			    ele:"#cost",
			    datatype:"decimal",
			    nullmsg:"请输入成本价！"
			},
			{
			    ele:"#marketPrice",
			    datatype:"decimal",
			    nullmsg:"请输入市场价！"
			},
			{
			    ele:"#weight",
			    datatype:"decimal",
			    nullmsg:"请输入重量！"
			},
			{
			    ele:"#stock",
			    datatype:"n",
			    nullmsg:"请输入库存！"
			}
		]);
			
		 // 增加商品图片
		 $("#addProductImage").click(function() {
		 	var trHtml = "<tr>";
			trHtml += "<td><input type=\"file\" name=\"productImages[" + productImageIndex + "].file\" class=\"productImageFile\"/></td>";
			trHtml += "<td><input type=\"text\" name=\"productImages[" + productImageIndex + "].title\" class=\"text\" maxlength=\"200\"/></td>";		
			trHtml += "<td><input type=\"text\" name=\"productImages[" + productImageIndex + "].orders\" class=\"text productImageOrder\" maxlength=\"9\" style=\"width: 50px;\" /></td>";	
			trHtml += "<td><a herf=\"javascript:;\" onclick=\"deleteProductImage(this)\">删除</a></td>";		
			trHtml += "</tr>";
			$("#productImageTable").append(trHtml);
			productImageIndex ++;
		});
	 });
	 
	 // 删除商品图片
	 function deleteProductImage(obj) {
		$this = $(obj);
		if(window.confirm("确认要删除？")){
			$this.closest("tr").remove();
		}
	}
</script>
</head>

<body>
	<form id="form1" name="form1" method="post" action="<%=basePath%>admin/product/update.shtml" enctype="multipart/form-data">
		<input type="hidden" name="id" value="${product.id}" />
		<ul id="tab" class="tab">
			<li><input type="button" value="基础信息" /></li>
			<li><input type="button" value="商品介绍" /></li>
			<li><input type="button" value="商品图片" /></li>
			<!-- 
			<li><input type="button" value="商品参数" /></li>
			<li><input type="button" value="商品属性" /></li>
			<li><input type="button" value="商品规格" /></li> 
			-->
		</ul>
		<table width="98%" class="input tabContent">
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">商品分类：</td>
				<td class="tdLeft">
					<select name="productCategoryId" id="productCategoryId">
						<c:forEach items="${productCategoryTree }" var="productCategory">
							<option value="${productCategory.id }" <c:if test="${not empty product.productCategory && product.productCategory.id == productCategory.id }">selected</c:if>>
								<c:if test="${productCategory.grade != 0 }">
									<c:forEach var="i" varStatus="status" begin="0" end="${productCategory.grade}">
										&nbsp;&nbsp;
									</c:forEach>
								</c:if>
								${productCategory.name }
							</option>
						</c:forEach>
					</select>
				</td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">编号：</td>
				<td class="tdLeft"><input id="sn" name="sn"
					size="30" class="input" value="${product.sn }"/>用当前时间精确到秒作为编码格式如20150101091010</td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">名称：</td>
				<td class="tdLeft"><input id="name" name="name"
					size="30" class="input" value="${product.name }"/></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">描述：</td>
				<td class="tdLeft"><input id="description" name="description"
					size="30" class="input" value="${product.description }"/></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">销售价：</td>
				<td class="tdLeft"><input id="price" name="price"
					size="30" class="input" value="<fmt:formatNumber value="${product.price }" pattern="0.00"/>"/></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">成本价：</td>
				<td class="tdLeft"><input id="cost" name="cost"
					size="30" class="input" value="<fmt:formatNumber value="${product.cost }" pattern="0.00"/>"/></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">市场价：</td>
				<td class="tdLeft"><input id="marketPrice"
					name="marketPrice" size="30" class="input" value="<fmt:formatNumber value="${product.marketPrice }" pattern="0.00"/>"/></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">重量：</td>
				<td  class="tdLeft"><input id="weight" name="weight"
					size="30" class="input" value="${product.weight }"/>kg</td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">库存：</td>
				<td class="tdLeft"><input id="stock" name="stock"
					size="30" class="input" value="${product.stock }"/></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">所有重量商品编号：</td>
				<td class="tdLeft"><input id="allWeightSn" name="allWeightSn"
					size="30" class="input" value="${product.allWeightSn }"/>用英文的;分隔 </td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">推荐配件商品编号：</td>
				<td class="tdLeft"><input id="recommendPartsSn" name="recommendPartsSn"
					size="30" class="input" value="${product.recommendPartsSn }"/>用英文的;分隔 </td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">推荐组合商品编号：</td>
				<td class="tdLeft"><input id="recommendGroupSn" name="recommendGroupSn"
					size="30" class="input" value="${product.recommendGroupSn }"/>用英文的;分隔 </td>
			</tr>
		</table>
		<table width="98%" class="input tabContent">
			<tr bgcolor="#EEF4EA">
				<td class="tdLeft"><textarea id="editor" name="introduction" class="editor" style="width: 100%;">${product.introduction }</textarea></td>
			</tr>
		</table>
		<table id="productImageTable" width="98%" class="input tabContent">
			<tr>
				<td colspan="10" align="right">
					<input type="button" value="添加商品图片" class="button" id="addProductImage">
				</td>
			</tr>
			<tr class="title">
				<td>
					图片
				</td>
				<td>
					标题
				</td>
				<td>
					顺序
				</td>
				<td>
					删除
				</td>
			</tr>
		</table>
		<!-- 
		<table width="98%" class="input tabContent">
			<tr bgcolor="#EEF4EA">
			</tr>
		</table>
		<table width="98%" class="input tabContent">
			<tr bgcolor="#EEF4EA">
			</tr>
		</table>
		<table width="98%" class="input tabContent">
			<tr bgcolor="#EEF4EA">
			</tr>
		</table> 
		-->
		<table width="98%">
			<tr bgcolor="#EEF4EA">
				<td height="36" colspan="10">
					<input type="button" value="确定" class="button" id="save"/>
					<input type="button" value="返回" class="button" onclick="location.href='<%=basePath%>admin/product/list.shtml'" />
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
